<template>
  <div class="parent" style="width: 100%;height: 100vh">

  </div>
</template>

<script>
import {clubTypeList, clubInsert, clubById, clubUpdate} from "@/api";
export default {
  name: "ClubTemp",
  data() {
    return {
      id: 0,
      name: '',
      username: '',
      content:'',
      pwd: '',
      clubTypes: [],
      clubType: ''
    }
  },
  created() {
    clubTypeList().then(result=>{
      this.clubTypes = result.data;
    });
    if (this.$route.query.id!=null && this.$route.query.id!='0'){
      let club = {
        id: this.$route.query.id,
      };
      clubById(club).then((result)=>{
        this.id = result.data.id;
        this.name = result.data.name;
        this.username = result.data.username;
        this.pwd = result.data.pwd;
        this.content = result.data.content;
        this.clubType = result.data.type;
      })
    }
  },
  methods: {
    addClub(){
      let club = {
        id: this.id,
        name: this.name,
        type: this.clubType,
        username: this.username,
        pwd: this.pwd,
        content: this.content
      };
      if (this.id === 0) {
        this.name = '';
        this.clubType = '';
        this.username = '';
        this.pwd = '';
        this.content = '';
        clubInsert(club);
      }else {
        this.$confirm('此操作将永久修改社团信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          clubUpdate(club).then(()=>{
            clubById(club).then((result)=>{
              this.id = result.data.id;
              this.name = result.data.name;
              this.username = result.data.username;
              this.pwd = result.data.pwd;
              this.content = result.data.content;
              this.clubType = result.data.type;
            })
          });
          this.$message({
            type: 'success',
            message: '修改成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消修改'
          });
        });
      }
    },

    blackClubList(){
      this.$router.push('/club/list')
    }
  }
}
</script>

<style scoped>
.inputMax{
  width: 200px;
}
.parent {
  position: relative;
}

.parent::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  opacity: 0.1;
  background-image: url("https://source.unsplash.com/random");
  background-size: cover;

  z-index: -10;
}
</style>
